<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<% String basepath = request.getContextPath(); %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <title>招聘管理系统【用户登录】</title>
    <link href="<%=basepath%>/resources/css/login.css" rel="stylesheet" type="text/css"/>
    <link href="<%=basepath%>/resources/js/plugins/layui/css/layui.css" rel="stylesheet" type="text/css"/>
</head>
<body>

<%--    <div id="loginhead"></div>--%>
    <div class="main">
            <%--            action="<%=basepath%>/loginSys?loginType=pwd" method="post"--%>
<%--            <form id="Validform" >--%>
                <div id="pwdLogin" >
                    <!-- 用户名 -->
                    <div class="username" style="background-color: rgba(255, 255, 255, 0.7);">
                        <em></em>
                        <input  name="username" type="text" placeholder="用户名"  style="border:0;">
                    </div>
                    <!-- 密码 -->
                    <div class="password" style="background-color: rgba(255, 255, 255, 0.7);">
                        <em ></em>
                        <input  name="password" placeholder="密码"  type="password">
                    </div>
                    <!-- 验证码 -->
                    <div class="vcode">
                        <div class="vcodeDiv1" > <input name="vcode"  placeholder="验证码"  type="*"> </div>

                        <img id="valiCode" src="<%=basepath%>/resources/captcha.jpeg" alt="验证码" title="单击替换验证码"/>
                    </div>
                    <!-- 登陆按钮 -->
                    <div class="login_btn">
                        <button class="btn_pwdlogin"  style="background-color: rgba(75,139,210,1);margin-left: 40px; ">登&nbsp;&nbsp;录</button>
                        <button class="btn_msglogin"  style="background-color: rgba(127,186,44,1);margin-left: 20px; "> 短信登录 </button>
                    </div>
                </div>
<%--            </form>--%>
            <%--    action="<%=basepath%>/loginSys?loginType=msg" method="post"--%>
<%--            <form id="msgValidform" >--%>
                <div id="msgLogin" style="display: none" >
                    <!-- 用户名 -->
                    <div class="username" style="background-color: rgba(255, 255, 255, 0.7);">
                        <em></em>
                        <input  name="username" type="text" placeholder="用户名"  style="border:0;">
                    </div>
                    <!-- 密码 -->
                    <div class="password" style="background-color: rgba(255, 255, 255, 0.7);">
                        <em ></em>
                        <input  name="password" placeholder="密码"  type="password">
                    </div>
                    <!-- 验证码 -->
                    <div class="vcode">
                        <div class="vcodeDiv1" > <input  name="msgvcode" placeholder="验证码"   type="password"> </div>
                        <div class="vcodeDiv2"> <a href='javascript:' class='validlink' id="">发送验证码</a></div>
                    </div>
                    <!-- 登陆按钮 -->
                    <div class="login_btn">
                        <button class="btn_pwdlogin"  style="background-color: rgba(127,186,44,1);margin-left: 40px; ">登&nbsp;&nbsp;录</button>
                        <button class="btn_msglogin"  style="background-color: rgba(75,139,210,1);margin-left: 20px; "> 短信登录 </button>
                    </div>
                </div>
<%--            </form>--%>
        <%--<form id="Validform" action="<%=basepath%>/loginSys?loginType=pwd" method="post">
        <div class="box" id="pwdLogin" >
            <table width="250" border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td><span>用户名：</span></td>
                    <td colspan="2"><input type="text" name="username" value=""   placeholder="请输入账号"  datatype="*" nullmsg="账号不能为空！"/>
                    </td>
                </tr>
                <tr>
                    <td><span>密　码：</span></td>
                    <td colspan="2"><input type="password" name="password" value="" placeholder="请输入密码" datatype="*"
                                           nullmsg="登录密码不能为空！" autocomplete="new-password" /></td>
                </tr>
                <tr>
                    <td width="60"><span>验证码：</span></td>
                    <td width="92"><input style="width:80px;" type="text" name="vcode" datatype="*" nullmsg="验证码不能为空！"/>
                    </td>
                    <td><img id="valiCode" src="<%=basepath%>/resources/captcha.jpeg" alt="验证码" title="单击替换验证码"/></td>
                </tr>
                <tr>
                    <td></td>
                    <td colspan="2">
                        <button type="submit">登&nbsp;&nbsp;录</button>&emsp;&emsp;&emsp;<a href="javascript:void;" id="btn_msglogin">短信登录>></a>
                    </td>
                </tr>
            </table>
        </div>
        </form>
        <form id="msgValidform" action="<%=basepath%>/loginSys?loginType=msg" method="post">
        <div class="box" id="msgLogin" style="display: none">
            <table width="250" border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td><span>用户名：</span></td>
                    <td colspan="2"><input type="text" name="username" value=""   placeholder="请输入员工号"  datatype="*" nullmsg="员工号不能为空！"/>
                    </td>
                </tr>
                <tr>
                    <td><span>密　码：</span></td>
                    <td colspan="2"><input type="password" name="password" value="" placeholder="请输入密码" datatype="*"
                                           nullmsg="登录密码不能为空！" autocomplete="new-password" /></td>
                </tr>
                <tr>
                    <td><span>验证码：</span></td>
                    <td width="92"><input style="width:80px;" type="password" name="msgvcode" datatype="*" nullmsg="验证码不能为空！" autocomplete="new-password"/></td>
                    <td><a href='javascript:' class='validlink' id="">发送验证码</a></td>
                    <td></td>
                </tr>

                <tr>
                    <td></td>
                    <td colspan="2">
                        <button type="submit">登&nbsp;&nbsp;录</button>&emsp;&emsp;&emsp;<a href="javascript:void;" id="btn_pwdlogin">>></a>
                    </td>
                </tr>
            </table>
        </div>
        </form>--%>
    </div>
<%--    <div id="loginfooter">CopyRight <span>©</span> 2020 重庆城市交通开发投资（集团）有限公司</div>--%>

<script src="<%=basepath%>/resources/js/jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="<%=basepath%>/resources/js/plugins/Validform/Validform_v5.3.2_min.js" type="text/javascript"></script>
<script src="<%=basepath%>/resources/js/actions.js" type="text/javascript"></script>
<script src="<%=basepath%>/resources/js/loginVerification.js" type="text/javascript"></script>
<script src="<%=basepath%>/resources/js/plugins/layui/layui.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
    var time=null;
    var maxtime = 45; //45秒!
    var loginMode = false;//fasle : 密码登录 ；   true: 短信登录

     $(function () {
        $("#valiCode").bind("click", function () {
            this.src = "<%=basepath%>/resources/captcha.jpeg?time=" + (new Date()).getTime();
        });

        if (window.top.location.href.toLowerCase().indexOf("/login") == -1) {
            window.top.location.href = window.location.href;
        }


        $('.validlink').on('click',getUserCode);

        function getUserCode() {
            var ucode = $('#msgLogin input[name=username]').val();
            if (ucode.length > 0) {
                $.ajax({
                    type:"POST",
                    url:"/SendVCode",
                    data:{username:ucode},
                    dataType:"json",
                    success:function(data){
                     //   $.Showmsg(data.Message);
                      //  console.log(data);
                        if (data.url != 'no') {
                            layui.use(['layer', 'form'], function(){
                                layer.alert('登录成功...',  {icon: 1}, function(index){
                              //      console.log("点击了确定按钮");
                                    clearInterval(timer);
                                    $('.validlink').removeAttr("disabled");
                                    $('.validlink').text("发送验证码");
                                    $('.validlink').on('click',getUserCode);

                                    layer.close(index);
                                });
                            });
                            location = data.url;
                        }else{
                            layui.use(['layer', 'form'], function(){
                                layer.alert(data.Message,  {icon: 2},  function(index){
                                //    console.log("点击了确定按钮");
                                    clearInterval(timer);
                                    $('.validlink').removeAttr("disabled");
                                    $('.validlink').text("发送验证码");
                                    $('.validlink').on('click',getUserCode);

                                    layer.close(index);
                                });
                            });
                        }
                    }
                });

                timer = setInterval(CountDown, 1000);

            } else {
                layui.use(['layer', 'form'], function(){
                    layer.alert('请输入员工号！', {icon: 2});
                });
            }
        }
        
        function CountDown() {
            if (maxtime >= 0) {
                $('.validlink').attr("disabled","disabled");
                $('.validlink').text("("+maxtime+")请稍等..");
                $(".validlink").off()
                --maxtime;
            } else {
                clearInterval(timer);
                $('.validlink').removeAttr("disabled");
                $('.validlink').text("发送验证码");
                $('.validlink').on('click',getUserCode);
            }
        }

        $(document).keydown(function (event) {
            if(event.keyCode == 27) {//ESC:27
                $("*").blur();//去掉焦点
                if ($(".layui-layer-btn0").length > 0) //判断弹窗是否打开，关闭弹窗
                    layer.closeAll();
            }
            if(event.keyCode == 13) {//ENTER:13
                $("*").blur();//去掉焦点
                if ($(".layui-layer-btn0").length > 0)//判断弹窗是否打开，关闭弹窗
                    layer.closeAll();
                else{
                    if(loginMode)//fasle : 密码登录 ；   true: 短信登录
                        goToLoginMsg();
                    else
                        goToLoginPassword();
                }
            }
        });

        // $(document).ready(function () { }).keydown(
        //     function (e) {
        //         if (e.which === 27) {
        //             layer.closeAll();
        //         }
        //     });

       /* $("#msgValidform").Validform({
            ajaxPost: true,
            callback: function (data) {
                if (data.url != 'no') {
                    $.Showmsg(data.Message + ' 马上跳转...');
                } else {
                    $.Showmsg(data.Message);
                }
                setTimeout(function () {
                    if (data.state) {
                        $.Hidemsg();
                    }
                    if (data.url != 'no') {
                        location = data.url;
                    }
                }, 2000);
            }
        });*/
    });
</script>
</body>
</html>
